/**
 * 图片浏览器
 */
(function($){
    var photoContainer = $('#photoContainer');
    var pre = $('#photoPre');
    var next = $('#photoNext');
    var midPhoto = $('#goods_img');
    
    var list = photoContainer.find('a');
    list.each(function(index, item){
		var that = $(this);
        that.bind('click', function(){
            midPhoto.attr('src', that.attr('img_url'));
			$('#jqzoom').attr('href', that.attr('img_original'));
			$('#big_img_url').attr('href', that.attr('href'));
            return false;
        });
    });
    
    var itemWidth = parseInt(photoContainer.children().eq(0).width());
    var maskWidth = 9 * itemWidth;
    photoContainer.width(list.length * itemWidth);
    photoContainer.css('margin-left', 0 + 'px');
    
    //alert(photoContainer.css('margin-left'));
    pre.bind('click', function(){
    
        var ml = parseInt(photoContainer.css('margin-left'));
        if (ml == 0) 
            return false;
        
        var step = ml + itemWidth;
        //alert(step);
        //photoContainer.css('margin-left', step + 'px');
        photoContainer.animate({
            'margin-left': step
        }, 200);
        return false;
    });
    
    next.bind('click', function(){
        var ml = parseInt(photoContainer.css('margin-left'));
        if (ml < (maskWidth - parseInt(photoContainer.width()))) {
            return false;
        }
        
        
        var step = ml - itemWidth;
        //alert(step);
        //photoContainer.css('margin-left', step + 'px');
        photoContainer.animate({
            'margin-left': step
        }, 200);
        return false;
	    
    });
}(jQuery));

/**
 * 评论弹层
 */
(function($){
	var red = $('#recommend');
	var showBtn = $('#comment_btn');
	var mask = $('#login_cover_div');
	//var redClose = $('#recommendClose');
	var redClose = $('.for_cancel');

	showBtn.click(function(){
		var pos = $(this).position();
		
		red.show(300);
		red.css('top', pos.top - 200);
		mask.show();

		var docw = $(document).width();
		var doch = $(document).height();

		mask.css({'width': docw, 'height': doch});
		return false;
	});

	redClose.click(function(){
		red.hide(200);
		mask.hide();
		return false;
	});

}(jQuery));
